import info from "@/static/js/enterpriseServer/info.js"
export default {
	data() {
		return {

			//分页参数
			pageShow: false,
			page: 1,
			pageSize: 10,
			shopStatus: 'nomore',
			isRefreshing: false,
			//主要数据
			serviceId: '',
			serviceObj: {},
			serviceInfo: {},
			serviceShopList: [],

			//导航栏切换
			tabCurrent: 0,
			tabList: [{
				id: 0,
				name: '服务介绍'
			},
			{
				id: 1,
				name: '公司简介'
			}
			]
		};
	},
	onLoad(e) {
		this.serviceId = e.id
		this.getDetail()
	},
	methods: {
		//获取不同的服务商类型
		getServiceType(type) {
			let text = "";
			switch (type) {
				case 1:
					text = "官方服务商";
					break;
				case 2:
					text = "金牌服务商";
					break;
				case 3:
					text = "银牌服务商";
					break;
				case 4:
					text = "铜牌服务商";
					break;
				case 5:
					text = "普通服务商";
					break;
			}
			return text;
		},

		//获取服务商详情
		async getDetail() {
			let obj = {
				page: this.page,
				pageSize: 10,
				id: this.serviceId
			}
			let res = await info.getServiceDetail(obj)
			if (res.code === 1) {
				this.serviceObj = res.data
				this.serviceInfo = res.data.info
				let arr = []
				if (this.page == 1) {
					this.serviceShopList = []
				}
				let newList = res.data.serviceshoplist.data
				console.log(newList.length >= this.pageSize, 'newList.length >= this.pageSize');
				if (newList.length >= this.pageSize) {
					this.shopStatus = 'more'
				} else {
					this.shopStatus = 'nomore'
				}
				let arr1 = arr.concat(newList)
				arr1.forEach(val => {
					let obj = {
						id: val.id,
						name: val.name,
						pic: val.pic.split(','),
						price: val.price,
					}
					this.serviceShopList.push(obj)
				})
				this.isRefreshing = false
				this.pageShow = true
			} else {
				this.$tools.msg(res.msg)
			}
		},
		//导航栏切换事件
		tabClick(e) {
			this.tabCurrent = e.index
		},
		//下拉刷新
		refresherrefresh() {
			this.isRefreshing = true;
			this.page = 1
			this.getDetail()
		},
		//上拉加载
		loadMore() {
			if (this.shopStatus == 'more') {
				this.page++
				this.getDetail()
			}
		},

		//跳转上商品详情
		goInfo(item) {
			uni.navigateTo({
				url: "/enterpriseServer/productInfo/index?id=" + item.id
			})
		},

		openKefu() {
			if (!uni.getStorageSync('token')) {
				this.$common.handleToken()
				return
			}
			uni.setStorageSync("to_zim_userid", this.serviceInfo.user_id);
			uni.navigateTo({
				url: '/enterpriseServer/chatRoom/index?id=' + this.serviceInfo.user_id
			})
		}
	}
}